package com.sg.business.management.labelprovider;

import org.bson.types.ObjectId;

import com.mobnut.db.model.ModelService;
import com.sg.business.model.ManagermentCategory;
import com.sg.business.model.WFHumanTaskSetting;
import com.sg.business.model.WorkDefinition;
import com.sg.widgets.commons.labelprovider.ConfiguratorColumnLabelProvider;
import com.sg.widgets.registry.config.ColumnConfigurator;

public class WFMCLabelProvider extends ConfiguratorColumnLabelProvider {

	public WFMCLabelProvider(ColumnConfigurator configurator) {
		super(configurator);
	}

	public WFMCLabelProvider() {
	}

	@Override
	public String getText(Object element) {
		if (element instanceof WFHumanTaskSetting) {
			WFHumanTaskSetting wfHumanTaskSetting = (WFHumanTaskSetting) element;
			ManagermentCategory managementCategory = wfHumanTaskSetting
					.getManagementCategory();
			if (managementCategory != null) {
				return managementCategory.getDesc();
			}
		} else if (element instanceof WorkDefinition) {
			WorkDefinition workDefinition = (WorkDefinition) element;
			ObjectId objectId = (ObjectId) workDefinition
					.getValue("managementcategory");
			if (objectId != null) {
				ManagermentCategory createModelObject = ModelService
						.createModelObject(ManagermentCategory.class, objectId);
				return createModelObject.getDesc();
			}
		} else if (element instanceof ManagermentCategory) {
			ManagermentCategory managermentCategory = (ManagermentCategory) element;
			ObjectId objectId = (ObjectId) managermentCategory
					.getValue(ManagermentCategory.F_INHERIT);
			if (objectId != null) {
				ManagermentCategory createModelObject = ModelService
						.createModelObject(ManagermentCategory.class, objectId);
				return createModelObject.getDesc();
			}
			return managermentCategory.getDesc();
		}
		return super.getText(element);
	}

}
